Const T, const T *, T * const, const T &, const T * & difference, const
Here T refers to a data type, which can be basic data types such as int, long, and doule, or class of its own type. A single const must be a constant, but are you confused
Use const whenever possible
One wonderful thing about const is that it allows you to specify a semantic constraint: a specific object should not be modified. The compiler will execute this constraint. It allows you to notify the compiler and other
Constraints for assigning values according to ansi c:
1. Both operands are pointers to compatible types with or without delimiters.
2. the type pointed to by the Left pointer must have all the qualifiers of the type pointed to by the right
Item 3: Use const whenever possible
By Scott Meyers
Translator: fatalerror99 (itepub's nirvana)
Release: http://blog.csdn.net/fatalerror99/
One wonderful thing about const is that it allows you to specify a semantic (semantic) Constraint: a specific
1. Defining constants(1) The const modifier variable, the following two kinds of definition form are essentially the same. It means that the variable value of the type with the Const modifier is immutable.
TYPE const VALUENAME = value;
Const thinking
1. What is const?A common type is a type described by the Type modifier Const. The values of variables or objects of a common type cannot be updated. (Of course, we can steal the bar for updating :)
2. Why is const introduced?The
Const is used to declare a constant, and when you do not want a value to be changed, use the const,const INT max && int const Max is no different, all can.Does not involve pointer const very well understood.Cases involving pointers:Conat int b=100,
Const is the abbreviation of constant, the meaning of "constant unchanged". The const-modified items are protected against accidental changes and can improve the robustness of the program. So many C + + programming books suggest: "Use const whenever
1. What is const?
A common type is a type described by the Type modifier Const. a variable or object Value of a common type cannot be updated.
. (Of course, we can steal the bar for updating :)
2. Why is const introduced?
The initial purpose
Const Usage Details
Object-oriented is an important feature of C ++.However, the optimizations added by C ++ on the basis of C are also very dazzling.Const can directly replace # define in C.The following points are very important, and the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.